package com.jams.goodox.activity.serve.enterprise;

import android.content.Intent;
import android.widget.ListView;

import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.hangzhou.jin.customview.LoadView;
import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.entity.ProjectFinancialItem;
import com.jams.goodox.utils.CollectionUtils;
import com.jams.goodox.utils.StringUtils;
import com.jams.goodox.utils.StyleUtil;
import com.jams.library.commonAdapter.ListCommonAdapter;
import com.jams.library.commonAdapter.ListCommonViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;


/**
 * 针对项目融资的ChooseList
 */
public class ChooseListForProjectFinancialActivity extends BaseActivity {
    @Bind(R.id.lv_choose)
    ListView lvChoose;
    @Bind(R.id.lv_empty)
    LoadView emptyView;
    public static final String TITLE_FINANCIAL = "TITLE_FINANCIAL";
    public static final String CHOOSE_FINANCIAL = "CHOOSE_FINANCIAL";
    public static final String CONTENT_FINANCIAL = "CONTENT_FINANCIAL";
    public static int RESULT_CODE_PROJECT_FINANCIAL = 100;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_choose_list_with_empty_view;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKey(this,getIntent().getStringExtra(TITLE_FINANCIAL));
        List<ProjectFinancialItem> chooseItems = (List<ProjectFinancialItem>) getIntent().getSerializableExtra(CHOOSE_FINANCIAL);
       final String content = StringUtils.newString(getIntent().getStringExtra(CONTENT_FINANCIAL));//获得的item内容
        if (chooseItems == null) {
            chooseItems = new ArrayList<>();
        }
        if (!CollectionUtils.hasData(chooseItems)) {
            emptyView.loadCompleteNoData(R.mipmap.holder_no_common,R.string.no_content);
            return;
        }else{
            emptyView.loadComplete();
        }
        lvChoose.setAdapter(new ListCommonAdapter<ProjectFinancialItem>(this, chooseItems, R.layout.choose_list_item) {
            @Override
            public void convert(ListCommonViewHolder helper, final ProjectFinancialItem item, int position) {
                helper.setText(R.id.tv_choose_name, item.name)
                        .setViewVisible(R.id.iv_choose,StringUtils.newString(item.name).equals(content))
                        .setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(int position) {
                                Intent intent = new Intent();
                                intent.putExtra(CHOOSE_FINANCIAL, item);
                                setResult(RESULT_CODE_PROJECT_FINANCIAL, intent);
                                finish();
                            }
                        });

            }
        });
    }
   
}
